package cn.fl.spdealer.service.impl;

import java.util.List;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.spdealer.service.ISplCommDishonestService;
import cn.fl.spdealer.transform.SplCommDishonestVOTransform;
import cn.fl.spdealer.vo.SplCommDishonestVO;
import sp.dealer.facade.dealer.api.ISplCommDishonestApiService;
import sp.dealer.facade.dealer.condition.SplCommDishonestQC;
import sp.dealer.facade.dealer.dto.SplCommDishonestDTO;

/**
 * @Description: 相关法院失信人记录 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class SplCommDishonestServiceImpl implements ISplCommDishonestService {

	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private ISplCommDishonestApiService splCommDishonestApiService;

	@Override
	public SplCommDishonestVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null;
		}
		//TODO 业务逻辑
		SplCommDishonestDTO dto = this.splCommDishonestApiService.selectById(id);
		return SplCommDishonestVOTransform.toVO(dto);
	}

	@Override
	public Long add(SplCommDishonestVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("新增对象不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null;
		}
		//TODO 业务逻辑
		return this.splCommDishonestApiService.add(SplCommDishonestVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("删除主键参数不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return false;
		}
		//TODO 业务逻辑
		return this.splCommDishonestApiService.removeById(id);
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
	@Override
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
			BaseLogUtils.newWebLogger("删除主键参数集合不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(SplCommDishonestVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("修改对象参数不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return false;
		}
		//TODO 业务逻辑
		return this.splCommDishonestApiService.modify(SplCommDishonestVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		//TODO 业务逻辑
		return this.splCommDishonestApiService.searchListPage(page);
	}

	@Override
	public List<SplCommDishonestVO> searchListSplCommDishonestVO(SplCommDishonestQC condition) throws BaseException {
		// TODO Auto-generated method stub
		if(null == condition){
			BaseLogUtils.newWebLogger("查询条件不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null;
		}
		return SplCommDishonestVOTransform.toVOList(this.splCommDishonestApiService.searchList(condition));
	}

	@Override
	public int batchAdd(List<SplCommDishonestVO> holderList) throws BaseException {
		// TODO Auto-generated method stub
		if(CollectionUtils.isEmpty(holderList)){
			return 0;
		}
		this.splCommDishonestApiService.batchAdd(SplCommDishonestVOTransform.toDTOList(holderList));
		return holderList.size();
	}
}
